package com.clkj.zhonghui.service.topic;

import com.clkj.zhonghui.dao.topic.TagMapper;
import com.clkj.zhonghui.pojo.topic.TopicTag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.Arrays;
import java.util.List;


/**
 * @Author：周佳润
 * @Date：2024/7/16 下午3:41
 */
@Service
public class TagServiceImpl implements TagService{

    @Autowired
    private TagMapper tagMapper;
    @Override
    public void addTag(String tagNames) {
        String[] name = tagNames.split(",");
        for (String tagName : name) {
            TopicTag topicTag = new TopicTag();
            topicTag.setTagName(tagName);
            tagMapper.insertSelective(topicTag);
        }
    }

    @Override
    public List<TopicTag> getTagList() {
        List<TopicTag> topicTags = tagMapper.selectAll();
        return topicTags;
    }

    @Override
    public void delTag(String ids) {
        String[] split = ids.split(",");
        Example example = new Example(TopicTag.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andIn("tagId", Arrays.asList(split));
        tagMapper.deleteByExample(example);
    }

}
